<?php
include_once "BaseM.php";
 
class LogUserActionM extends BaseM{
	
	public $table = "log_user_action";
	
	public function __construct() {
		parent::__construct ();
	}

	/**
	 * 新增
	 */
	public function insert($obj) {
		$sql = $this->genInserSQL($this->table, $obj);
		$result = @mysql_query($sql) or die ("sql : ".$sql.'\n'.mysql_error ());
		return $result;
	}

	/**
	 *取得全部
	 */
	public function queryTable($orderData, $startPage, $pageRow, $searchStr) {
		$whereStr = " 1 = 1 $searchStr ";
		
		$countSql = "select count(*) as count from $this->table where $whereStr ";
		
		$resultSql = "
			select 
				user_id, ip, action_area, action_type, date_modify,
				case action_type when 1 then '新增'
							  	 when 2 then '修改'
							  	 when 3 then '刪除'
							  	 when 4 then '其他'
				end action_type2,
				(select name from user where id = $this->table.user_id ) as user_name
			from $this->table
			where $whereStr
			order by $orderData 
			limit $startPage, $pageRow ";
		
		return array( "count" =>  $this->querySQL($countSql, true)->count, "result" => $this->querySQL($resultSql) );
	}
	
	public function queryArea(){
		$resultSql = " select action_area from $this->table group by action_area ";
		return $result = $this->querySQL($resultSql);
	}

}

?>